import BaseService from './_BaseService'
import config from "../config";
import axios from "axios";

class MessageService extends BaseService {
  root = window.apiPath + '/messages';

  setReadStatus (id, status = 1) {
    return super.put(window.apiPath + '/messages-status', {id, status})
  }

  ps (page, query = '', status = 1, pageSize = config.PAGE_SIZE) {
    return axios.get(config.SERVER_URL + window.apiPath + `/messages-ps?page=${page}&size=${pageSize}&query=${query}`, {responseType: 'json'})
      .then(resp => {
        return {
          dataCount: parseInt(resp.headers['x-total-count'], 10),
          data: resp.data
        }
      })
  }
  delete (id) {
    return axios.delete(config.SERVER_URL + window.apiPath + '/messages/' + id, {responseType: 'json'})
      .then(resp => {
        return resp
      })
  }
}

export default new MessageService()
